***Table 1: Demographic characteristics at baseline and across groups
*using data from recruitment
cd ""

use "demog_adults_edi_essex_shared.dta", clear

**merging with show ups to exclude participants who answered during recruitment but did not show up
joinby id edi  using "sessions_showups.dta", unmatched(both)

tab _merge
**keeping only with participants present at year 1
keep if _merge==3

/*Nb of families by treatment present at session 1*/
sort id hh_id

gen same_fam=1 if hh_id[_n]==hh_id[_n-1]
bys treatment : tab same_fam, mi /*the missing values corresponds to unique hh_id hence indicating the number of families in each treatment to start with 111 in the control, 103 in Meal, 71 in Snack*/

/*perc of females*/
gen female=1 if gender2==2
replace female=0 if gender2==1

gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1
tab meal_control

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1
tab snack_control


bys treatment: tab female
prtest female, by(meal_control)
prtest female, by(snack_control)

/*perc of pregnant*/
bys treatment: tab pregnant if female==1, nolab
gen pregnant_yes=1 if pregnant==1
replace pregnant_yes=0 if pregnant==2
prtest pregnant_yes if female==1, by(meal_control)
prtest pregnant_yes if female==1, by(snack_control)

/*nb of adults and children in household*/
preserve 

collapse  nr_adults_household nr_children_household edi treatment meal_control snack_control , by(hh_id)
bys treatment: su nr_adults_household 
ttest nr_adults_household, by(meal_control)
ttest nr_adults_household, by(snack_control)

bys treatment: su nr_children_household
ttest nr_children_household, by(meal_control)
ttest nr_children_household, by(snack_control)

restore

/*Age adult*/ 
gen age=2015-yearofbirth 
replace age=. if yearofbirth==.
count if age==. /*191 missing*/
bys treatment: su age
ttest age, by(meal_control)
ttest age, by(snack_control)

/*Age child*/ 
preserve
use "master_data_adults_child_s13456_shared.dta", clear 
keep if session==1 & child==1
bys treatment: su age 
ttest age, by(meal_control)
ttest age, by(snack_control)
restore

/*Income*/
bys treatment: su h_income_annual_imp
ttest h_income_annual_imp, by(meal_control)
ttest h_income_annual_imp, by(snack_control)

/*benefits: using only recruitement data, that is when we collected the information*/
preserve
drop _merge

use "recruitment_essex_simplified_2NB_shared.dta", clear
gen edi=0
rename childbenefit h_earning_child_benefit
rename tax_children_credit h_earning_tax_credit
rename job_allowance h_earning_job_allowance
rename housing_benefit h_earning_housing_benefit
rename income_support h_earning_income_support
rename other_state_benefit h_earning_other_benefits	   
replace hh_id="3794433" if hh_id=="2794433"
replace hh_id="3165533" if hh_id=="3165522"
sort hh_id
append using "recruitment_edi_benefits_byhh_idNB1.dta"

joinby hh_id using "sessions_showups.dta", unmatched(both)

gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1

foreach v of var  h_earning_child_benefit h_earning_tax_credit  h_earning_job_allowance h_earning_housing_benefit h_earning_income_support h_earning_other_benefits{
replace `v'=0 if `v'==. 
}

eststo clear
eststo: qui estpost  sum h_earning_child_benefit h_earning_tax_credit  h_earning_job_allowance h_earning_housing_benefit h_earning_income_support h_earning_other_benefits if treatment==1
eststo: qui estpost  sum h_earning_child_benefit h_earning_tax_credit  h_earning_job_allowance h_earning_housing_benefit h_earning_income_support h_earning_other_benefits if treatment==2
eststo: qui estpost  sum h_earning_child_benefit h_earning_tax_credit  h_earning_job_allowance h_earning_housing_benefit h_earning_income_support h_earning_other_benefits if treatment==3
esttab using "sources_benefit.xls", cells("mean(fmt(%8.3f)) sd(fmt(%8.2f)) count(fmt(0))") tab label collabels("Mean" "Std. Dev.")   title("Sources of incomes")  addnotes("")  nonumber noobs replace
 
/*tests*/ 
foreach v of var  h_earning_child_benefit h_earning_tax_credit  h_earning_job_allowance h_earning_housing_benefit h_earning_income_support h_earning_other_benefits{
prtest `v', by(meal_control)
prtest `v', by(snack_control)
}
restore

/*Education*/
preserve
use "master_data_adults_child_s13456_shared.dta", clear 
drop meal_control snack_control
gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1
tab meal_control

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1
tab snack_control
keep if session==1 & child==0
drop if educational_qualifications==.  /*some for which we don't have the information*/

*educational_qualifications coding
*4 School leaving certificate, NQ unit
*5 O grade, standard grade GCSE..
*6 GNVQ/GSVQ foundation or intermediate, SVQ level
*8 higher grade, andvanced higher, CSYS, A level
*9 GNVQ/GSVQ advanced, SVQ level 3
*10 HNC HND SVA level 4 RSA higher diploma
*11 First degree, higher degree, SVQ level 5
*12 Profesionnal qualifications eg teaching accountancy
*13 Other school examination not already mentioned
*15 Other post school but pre higher education
*16 Other higher education qualifcation
*17 No qualifications

/*No qualification*/
gen no_qual=1 if educational_qualifications==17
replace no_qual=0 if educational_qualifications!=17 
bys treatment:  tab no_qual 
prtest no_qual, by(meal_control)
prtest no_qual, by(snack_control)

/*Higer degree of education*/ 
gen higer_degree=1 if educational_qualifications==11  |  educational_qualifications==16  |  educational_qualifications==12
replace higer_degree=0 if higer_degree==. 

bys treatment:  tab higer_degree 
 
prtest higer_degree, by(meal_control)
prtest higer_degree, by(snack_control)
restore
